#ifndef _BORROWER_H_
#define _BORROWER_H_

#include <string>
#include <list>

class Book_t;

class Borrower_t
{
public:

	/**
	* Will assign IDs to borrowers
	*/
	static unsigned long ids;

	/**
	* CTOR
	**/
	explicit Borrower_t(const std::string& name);

	/**
	* DTOR
	*/
	virtual ~Borrower_t();

	/**
	* Return reader's ID
	*/
	inline size_t id() const
	{
		return m_id;
	}

	/**
	* Return borrower's name
	*/
	inline const std::string& name() const
	{
		return m_name;
	}

	/**
	* Add book to borrowed list
	*/
	virtual int addBorrowed(Book_t* const book);

	/**
	* Return true if book is already borrowed by the borrower
	*/
	bool alreadyBorrowed(Book_t* const book) const;

	/**
	* Return 1 on success
	* Return 0 on success and when there is a borrower waiting for that book
	* Return -1 on failure (i.e. book doesn't exist)
	*/
	virtual int returnBook(Book_t* book);

	/*
	* Return true if a borrower can be removed from library- he is not borrowing any books at the moment
	*/
	inline bool safeToRemove() const
	{
		return (m_borrowed.empty() && m_waitingCount==0);
	}

	/**
	* Print borrower report
	*/
	virtual std::string borrowerReport() const;

	/**
	* Operator==
	*/
	virtual bool operator==(const Borrower_t* other) const;

	/**
	* Decrease waiting counter
	*/
	inline void decWaitingCounter()
	{
		m_waitingCount--;
	}


private:
	/**
	* Reader's name
	*/
	std::string m_name;

	/**
	* Reader's ID
	*/
	unsigned long m_id;

	/**
	* List of borrowed books
	*/
	typedef std::list<Book_t*> borrowedList;
	borrowedList m_borrowed;

	/**
	* A counter to tell the number of books the borrower is one their waiting list
	*/
	size_t m_waitingCount;

	/**
	* Operator<<
	*/
	friend std::ostream& operator<<(std::ostream& os, const Borrower_t& other);

	/**
	* COPY CTOR - no implementation
	*/
	Borrower_t(const Borrower_t& other);

	/**
	* Operator= - no implementation
	*/
	Borrower_t& operator=(const Borrower_t& other);
};

#endif // _BORROWER_H_